package com.lyl.syt.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.syt.common.result.Result;
import com.lyl.syt.model.user.UserInfo;
import com.lyl.syt.service.UserInfoService;
import com.lyl.syt.vo.user.UserInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
@RequiredArgsConstructor
public class UserController {
    private final UserInfoService userInfoService;

    @GetMapping("/{page}/{limit}")
    public Result<IPage<UserInfo>> list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo queryVo){
        Page<UserInfo> pageParam = new Page<>(page,limit);
        IPage<UserInfo> iPage = userInfoService.selectPage(pageParam,queryVo);
        return Result.ok(iPage);
    }

    @ApiOperation("用户锁定")
    @GetMapping("/lock/{userId}/{status}")
    public Result<Boolean> lock(@PathVariable Long userId, @PathVariable Integer status){
        return Result.ok(userInfoService.lock(userId,status));
    }

    @ApiOperation("用户详情")
    @GetMapping("/show/{userId}")
    public Result<Map<String,Object>> show(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation("认证审批")
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result<Boolean> approval(@PathVariable Long userId, @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
